package com.laikan.reader.bookfriend.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.laikan.library.components.activitys.BasicActivity;
import com.laikan.library.utils.SPUtil;
import com.laikan.reader.R;
import com.laikan.reader.bookstore.activity.ClassTwo;
import com.laikan.reader.core.utils.PublicUtil;
import com.socks.library.KLog;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;

/**
 * @author wx
 * @category 充值页面
 */
@SuppressLint ("HandlerLeak")
public class RechargePage extends BasicActivity implements OnClickListener {

    /**
     * type 1. 支付宝 2. 财付通 3. 网上银行 4. 微信支付  5.v付宝支付  6.QQ钱包支付
     */
    private ImageView  weixin;
    private int type;
    private ArrayList<Integer> payratio = new ArrayList<Integer>();
    private boolean payAction;
    private TextView  text_msg, text_msg_bu;
    private ImageView back_tv;
    Drawable drawable_back_tv;
    private RelativeLayout back_layout;
    private ImageView zhifubao;
    private ImageView qq_wallet;

    @Override
    protected void onResume() {
        MobclickAgent.onEvent(mContext, "cznum");
        super.onResume();
    }

    @Override
    protected void assignViews() {
        setContentView(R.layout.rechargepage);
        zhifubao = (ImageView)findViewById(R.id.zhifubao);
        back_layout = (RelativeLayout)findViewById(R.id.back_layout);
        back_tv = (ImageView)findViewById(R.id.iv_back);
        text_msg = (TextView)findViewById(R.id.text_msg);
        text_msg_bu = (TextView)findViewById(R.id.text_msg_bu);
        weixin = (ImageView)findViewById(R.id.weixin);
        qq_wallet = (ImageView)findViewById(R.id.qq_wallet);
        weixin.setOnClickListener(this);
        zhifubao.setOnClickListener(this);
        qq_wallet.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        drawable_back_tv = new BitmapDrawable(PublicUtil.getAlphaBitmap(PublicUtil.readBitMap(mContext, R.drawable.lk_back_small), Color.parseColor("#66ccdd")));
        back_tv.setImageDrawable(drawable_back_tv);
        payratio = getIntent().getIntegerArrayListExtra("payratio");
        KLog.e("RechargePage ---------payratio----"+payratio);
        payAction = getIntent().getBooleanExtra("payAction", false);
        KLog.e("RechargePage --------payAction-----"+payAction);
        if (SPUtil.getBoolean("signedAction", false)) {
            text_msg.setVisibility(View.VISIBLE);
            text_msg_bu.setVisibility(View.VISIBLE);

        }else {
            text_msg.setVisibility(View.GONE);
            text_msg_bu.setVisibility(View.GONE);
        }
    }

    @Override
    protected void setListener() {
        back_layout.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.weixin:
                    type = 4;
                    disposeData();
                break;
            case R.id.zhifubao:
                type = 1;
                disposeData();
                break;
            case R.id.qq_wallet:
                type = 6;
                disposeData();
                break;
            case R.id.back_layout:
                finish();
                break;
            default:
                break;
        }
    }

    public void disposeData() {
        if (type != 5) {

            Intent intent = new Intent(this, MoneyPage.class);
            intent.putExtra("type", type);
            intent.putIntegerArrayListExtra("payratio", payratio);
            intent.putExtra("payAction", payAction);
            startActivity(intent);
        }else {
            startActivity(new Intent().setClass(mContext, VPayMoney.class).putExtra("payAction", payAction));
        }

    }

    // TODO: 9/13/16 checkhere
    public void setView(String url) {
        Intent intent = new Intent(this, ClassTwo.class);
        intent.putExtra("mHtmlUrl", url);
        intent.putExtra("title", getString(R.string.rechargepage_title_value));
        startActivity(intent);
    }

}
